//
//  main.m
//  RuntimeTow
//
//  Created by  赵薇 on 15/12/24.
//  Copyright © 2015年 MoNa. All rights reserved.
//

#import <Foundation/Foundation.h>
//银头文件
#import <objc/runtime.h>
#import <objc/message.h>

@interface Person : NSObject    

@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *sex;
@property (nonatomic, assign) NSInteger age;
@property (nonatomic, copy) NSString *hobby;

- (void)foo;



@end

@implementation Person

- (void)foo {
    NSLog(@"11111111111111");
}

@end


int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        //NSLog(@"Hello, World!");
        
        Person *per = [[Person alloc] init];
        
        per.name = @"wowo";
        per.sex = @"nn";
        per.age = 12;
        per.hobby = @"玩狗";
        
        
        //1 获取per的类名
        Class class = [per class];
        
        const char *className = class_getName(class);
        NSLog(@"%s", className);
        
        // 2 meta-class 元类
        
        // 1> 当我们调用实例化方法时, 系统回去类的列表里去找对应名字的方法
        // 2> 当我们调用类方法时, 系统回去meta-class(元类)的列表中对应的名字的方法
        
        //寻找对象的元类, Object_getClass(类的对象)
        
        Class metaClass = object_getClass(class);
        
        BOOL isMetaClass = class_isMetaClass(metaClass);
        
        NSLog(@"是不是元类%d", isMetaClass);
        
        // 3 获取成员变量
        unsigned int count = 0; //无符号的整形
        
        Ivar *ivarList = class_copyIvarList(class, &count);
        
        //循环遍历类, 获取其成员变量
        for (int i = 0; i < count; i++) {
            
            Ivar ivar = ivarList[i];
            NSLog(@"Person类中的属性列表的下标:%d属性名%s", i, ivar_getName(ivar));
            
        }
        
        
        // 4 获取属性列表
        
        unsigned int outCount = 0;
        objc_property_t *properList = class_copyPropertyList(class, &outCount);
        
        //循环遍历属性列表
        
        for (int i = 0; i < outCount; i++) {
            
            objc_property_t prop = properList[i];
            NSLog(@"Pereson类中的属性列表的下标:%d的属性名称:%s", i, property_getName(prop));
            
            unsigned int attributeCount = 0;
            
           objc_property_attribute_t *attribute = property_copyAttributeList(prop, &attributeCount);
            
            for (int j = 0; j < attributeCount; j++) {
                NSLog(@"^^^^^^^^^^^%s%s",attribute[j].name, attribute[j].value);
            }
            
        }
        
        // 获取方法列表
        
        unsigned int methodCout = 0;
        Method  *methodList = class_copyMethodList(class, &methodCout);
        
        
        for (int i = 0; i < methodCout; i++) {
            
            Method med = methodList[i];
            NSLog(@"----------%d,**********%@", i, NSStringFromSelector(method_getName(med)));
            
        }
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    }
    return 0;
}
